import { addCount,
  addCart } from 'store/mutations-type';

export default {
  addCart(context, goodData) {
    return new Promise((resolve, reject) => {
      let has = context.state.cartList.find(item => { // 判断是否存在同名id
        return item.id == goodData.id;
      })
  
      if(has == undefined) { // 如果同名+1
        context.commit(addCart, goodData);
        resolve('添加到购物车');
      } else { // 没有就push
        context.commit(addCount, has);
        resolve('数量+1');
      }
    })
    
  }
}